import 'package:flutter/material.dart';

class AnimatedSwicherPage extends StatefulWidget {
  @override
  _AnimatedSwicherPageState createState() => _AnimatedSwicherPageState();
}

class _AnimatedSwicherPageState extends State<AnimatedSwicherPage> {
  bool isHello = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('模板'),
        ),
        body: Container(
          alignment: Alignment.center,
          child: LayoutBuilder(
            builder: (context, constraints) {
              print('$constraints');
              return Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    color: Colors.orange,
                    width: 200,
                    height: 200,
                    child: AnimatedSwitcher(
                      duration: Duration(milliseconds: 1000),
                      transitionBuilder: (child, animation) {
                        return ScaleTransition(
                          scale: animation,
                          child: FadeTransition(
                            opacity: animation,
                            child: child,
                          ),
                        );
                      },
                      child: Text(
                        isHello ? 'Hello' : 'Welcome',
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 30,
                            fontWeight: FontWeight.bold),
                        key: UniqueKey(),
                      ),
                    ),
                  ),
                  ElevatedButton(
                      onPressed: () {
                        setState(() {
                          isHello = !isHello;
                        });
                      },
                      child: Text('切换widget')),
                  SizedBox(
                    height: 80,
                    width: 1,
                  ),
                  TweenAnimationBuilder(
                      tween: Tween(begin: 1.0, end: 6.0),
                      duration: Duration(milliseconds: 2000),
                      builder: (ctx, value, child) {
                        return Transform.scale(
                          scale: value,
                          child: Text('测试动画'),
                        );
                      }),
                  ElevatedButton(onPressed: () {}, child: Text('切换widget')),
                ],
              );
            },
          ),
        ));
  }
}
